function main(ctx, objects) {
    let lastTime = Date.now();
    const tick = 10;
    setInterval(() => {
        ctx.clearRect(0, 0, 800, 500);
        objects.forEach((obj) => {
            obj.animation && obj.animation(lastTime);
            obj.draw(ctx);
            obj.doTimer && obj.doTimer();
        });
        ctx.fillStyle = '#f2ebe8';
        ctx.fillText(getFps(tick), 10, 10, 200);
        ctx.fillStyle = '#000';
        ctx.fillText('使用A键向左移动，D键向右移动', 10, 480, 200);
        lastTime = Date.now();
    }, tick);
    let fpsTickCnt = 0;
    let fpsSum = 0;
    let fpsStr = '';
    function getFps(tick) {
        let loopCnt = 1000 / tick;
        fpsTickCnt ++;
        let interval = Date.now() - lastTime;
        fpsSum += interval;
        if (fpsTickCnt >= loopCnt) {
            let fps = 1000 / (fpsSum *1./fpsTickCnt) ;
            fpsStr = 'fps : ' + fps.toFixed(1);
            fpsSum = 0;
            fpsTickCnt = 0;
        }
        return fpsStr;
    }
    window.onkeydown = function(ev) {
        if (ev.keyCode == 37) {

        } else if (ev.keyCode == 39) {
            
        } else if (ev.keyCode == 65) {
            // player1 left
            player1.move(-1);

        } else if (ev.keyCode == 68) {
            // player1 right
            player1.move(1);
        }
    }

    window.onkeyup = function(ev) {
        if (ev.keyCode == 37) {

        } else if (ev.keyCode == 39) {
            
        } else if (ev.keyCode == 65) {
            // player1 left
            player1.stop();
            
        } else if (ev.keyCode == 68) {
            // player1 right
            player1.stop();
        } else if (ev.keyCode == 32) {
            player1.attack();
        }
    }
}